package com.ei.itop.stat.service.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ailk.dazzle.util.ibatis.GenericDAO;
import com.ailk.dazzle.util.type.DateUtils;
import com.ei.itop.stat.service.IncidentStatService;
@Service
public class IncidentStatServiceImpl implements IncidentStatService{

	@Resource(name = "app.siCommonDAO")
	private GenericDAO exeDAO;
	
	public void statIncidentsDay(Date curDate) throws Exception {
		Date yesterday = DateUtils.dateOffset(curDate, Calendar.DAY_OF_YEAR, -1);
		//取到昨天的日期
		String statDateStr = DateUtils.date2String(yesterday, DateUtils.FORMATTYPE_yyyy_MM_dd);
		//按日的统计范围
//		Date statStartDate = DateUtils.string2Date(DateUtils.date2String(yesterday, DateUtils.FORMATTYPE_yyyy_MM_dd)+" 00:00:00", DateUtils.FORMATTYPE_yyyy_MM_dd_HH_mm_ss);
//		Date statEndDate = DateUtils.string2Date(DateUtils.date2String(curDate, DateUtils.FORMATTYPE_yyyy_MM_dd)+" 00:00:00", DateUtils.FORMATTYPE_yyyy_MM_dd_HH_mm_ss);
		//按周统计范围
		Date statStartDate= DateUtils.string2Date(DateUtils.date2String(DateUtils.dateOffset(curDate, Calendar.DAY_OF_YEAR, -7), DateUtils.FORMATTYPE_yyyy_MM_dd)+" 00:00:00", DateUtils.FORMATTYPE_yyyy_MM_dd_HH_mm_ss);
		Date statEndDate = DateUtils.string2Date(DateUtils.date2String(curDate, DateUtils.FORMATTYPE_yyyy_MM_dd)+" 00:00:00", DateUtils.FORMATTYPE_yyyy_MM_dd_HH_mm_ss);
		//放入统计参数
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("statDateStr", statDateStr);
		params.put("statStartDate", statStartDate);
		params.put("statEndDate", statEndDate);
		//统计未完成事件
		exeDAO.execStatement("XC_INCIDENT.statUnsolvedIncidents", params);
		//统计接收到事件
		exeDAO.execStatement("XC_INCIDENT.statReceivedIncidents", params);
		//统计解决的事件
		exeDAO.execStatement("XC_INCIDENT.statFinishedIncidents", params);
	}
}
